package com.crowdfunding.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.crowdfunding.entity.CrowdfundingImage;
import com.crowdfunding.mapper.CrowdfundingImageMapper;
import com.crowdfunding.service.ICrowdfundingImageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaoyu
 * @since 2021-07-19
 */
@Service
public class CrowdfundingImageServiceImpl extends ServiceImpl<CrowdfundingImageMapper, CrowdfundingImage> implements ICrowdfundingImageService {

    @Autowired
    CrowdfundingImageMapper imageMapper;


    @Override
    public void addimages(String cfId, List<String> urls) {
//        List<CrowdfundingImage> images=new ArrayList<>();

        for (String url: urls
             ) {
            CrowdfundingImage crowdfundingImage=new CrowdfundingImage();
            crowdfundingImage.setImageUrl(url);
            crowdfundingImage.setCfId(cfId);
//            images.add(crowdfundingImage);
            imageMapper.insert(crowdfundingImage);
        }

    }

    @Override
    public List<CrowdfundingImage> getImageListByCfId(String cfId) {
        QueryWrapper<CrowdfundingImage> wrapper=new QueryWrapper<>();
        wrapper.eq("cf_id",cfId);
        List<CrowdfundingImage> crowdfundingImages=imageMapper.selectList(wrapper);
        return crowdfundingImages;
    }

    @Override
    public void deleteImageById(int imgId) {
        imageMapper.deleteById(imgId);
    }
}
